/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.cef.variable.dtgenerator.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.inspur.edp.cef.entity.config.MgrConfig;
import com.inspur.edp.cef.variable.dtgenerator.VariableGeneratorContext;
import org.springframework.core.serializer.Serializer;

public class VarConfigGenerator
{
	private VariableGeneratorContext parentContext;

	public VarConfigGenerator(VariableGeneratorContext parentContext, String apiAssemblyName, String coreAssemblyName)
	{
		this.parentContext = parentContext;
		this.privateApiAssemblyName = apiAssemblyName;
		this.privateCoreAssemblyName = coreAssemblyName;
	}



	public final String GetMgrConfigString()
	{
		MgrConfig tempVar = new MgrConfig();
		tempVar.setAllInterfaceAssembly(getApiAssemblyName());
		tempVar.setAssembly(getApiAssemblyName());
		tempVar.setAllInterfaceClassName(parentContext.getMgrAllInterfaceType().getFullName());
		tempVar.setClass(parentContext.getMgrInterfaceType().getFullName());
		tempVar.setImpAssembly(getCoreAssemblyName());
		tempVar.setImpClass(parentContext.getMgrImplType().getFullName());
		MgrConfig config = tempVar;
		ObjectMapper mapper = new ObjectMapper();
		SimpleModule module = new SimpleModule();
		mapper.registerModule(module);
		try {
			return (mapper.writeValueAsString(config));
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}

	private String privateApiAssemblyName;
	private String getApiAssemblyName()
	{
		return privateApiAssemblyName;
	}

	private String privateCoreAssemblyName;
	private String getCoreAssemblyName()
	{
		return privateCoreAssemblyName;
	}

	//public void Generate()
	//{
	//    config = new MgrConfig
	//    {
	//        AllInterfaceAssembly = parentContext.MgrAllInterfaceType.Assembly.FullName,
	//        Assembly = parentContext.MgrInterfaceType.Assembly.FullName,
	//        AllInterfaceClassName = parentContext.MgrAllInterfaceType.FullName,
	//        Class = parentContext.MgrInterfaceType.FullName,
	//        ImpAssembly = parentContext.MgrAssemblyName,
	//        ImpClass = parentContext.MgrImplType.FullName
	//    };
	//}
	//public void ConfigToStr()
	//{
	//    Generate();
	//    parentContext.VarConfigAttrStr=Serializer.JsonSerialize(config);
	//}
}
